<template>
	<view class="productInformation">
		<view class="productInformation-main">
			<view class="productInformation-title">
				<text class="productInformation-title-txt1"></text>
				<text class="productInformation-title-txt2 font_blod">包装类型标准</text>
			</view>
			<view class="productInformation-content">
				<textarea v-model="partsAttention" maxlength="-1" class="productInformation-content-text" value="" placeholder-class="inputplace" placeholder="请输入包装类型标准" />
			</view>
			<view class="productInformation-title">
				<text class="productInformation-title-txt1"></text>
				<text class="productInformation-title-txt2 font_blod">质量标准说明</text>
			</view>
			<view class="productInformation-content">
				<textarea v-model="partsInstructions" maxlength="-1" class="productInformation-content-text" value="" placeholder-class="inputplace" placeholder="质量标准说明" />
			</view>
			<view class="productInformation-title">
				<text class="productInformation-title-txt1"></text>
				<text class="productInformation-title-txt2 font_blod">质保方式说明</text>
			</view>
			<view class="productInformation-content">
				<textarea v-model="partsDamageDetails" maxlength="-1" class="productInformation-content-text" value="" placeholder-class="inputplace" placeholder="质保方式说明" />
			</view>
		</view>
		
		<view class="font_blod">
			<view v-if="show_btn" @click="cli_btn" class="productInformation-btm">
				保存
			</view>
			<view v-else @click="cli_btn" class="productInformation-btm productInformation-btm-false">
				保存
			</view>
		</view>
		
	</view>
</template>

<script>
	import allapi from '../api/index.js'
	export default {
		data() {
			return {
				partsId: '',
				partsDamageDetails: '', // 质保方式说明
				partsAttention: '', // 包装类型标准
				partsInstructions: '', // 质量标准说明
			}
		},
		onLoad(val) {
			this.partsId = val.id
		},
		computed: {
			show_btn () {
				let partsId = this.partsId
				let partsAttention = this.partsAttention
				let partsInstructions = this.partsInstructions
				let partsDamageDetails = this.partsDamageDetails
				if (partsAttention || partsInstructions || partsDamageDetails) {
					return true
				}else {
					return false
				}
			}
		},
		mounted() {
			this.getFactoryPartsDetails()
		},
		methods: {
			// 点击保存按钮
			cli_btn () {
				let partsId = this.partsId
				let partsAttention = this.partsAttention
				let partsInstructions = this.partsInstructions
				let partsDamageDetails = this.partsDamageDetails
				if (partsAttention || partsInstructions || partsDamageDetails) {
					this.updatePartsInstructions()
				}else {
					uni.showToast({
						title: '请先完善信息',
						icon: 'none'
					})
				}
			},
			// 保存信息
			updatePartsInstructions () {
				uni.request({
					url: allapi.updatePartsInstructions,
					data: {
						partsId: this.partsId,
						partsDamageDetails: this.partsDamageDetails,
						partsAttention: this.partsAttention,
						partsInstructions: this.partsInstructions
					},
					success: (res) => {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						setTimeout( () => {
							uni.navigateBack()
						}, 500)
					}
				})
			},
			// 获取信息
			getFactoryPartsDetails () {
				uni.request({
					url: allapi.getFactoryPartsDetails,
					data: {
						partsId: this.partsId
					},
					success: (res) => {
						console.log(res);
						let dat = res.data.data
						this.partsDamageDetails = dat.partsDamageDetails
						this.partsInstructions = dat.partsInstructions
						this.partsAttention = dat.partsAttention
					}
				})
			},
		}
	}
</script>

<style scoped>
	.productInformation {
		position: absolute;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		display: flex;
		flex-direction: column;
	}
	.productInformation-main {
		flex: 1;
		overflow: auto;
	}
	.productInformation-title {
		display: flex;
		align-items: center;
		margin: 24rpx;
	}
	.productInformation-title-txt1 {
		width: 10rpx;
		height: 34rpx;
		background: #5DD4D6;
		border-radius: 5rpx;
	}
	.productInformation-title-txt2 {
		font-size: 32rpx;
		color: #333333;
		margin-left: 24rpx;
	}
	.productInformation-content {
		margin: 24rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		height: 264rpx;
		padding: 24rpx;
	}
	.productInformation-content-text {
		width: 100%;
		height: 100%;
		font-size: 24rpx;
		font-weight: 400;
		color: #666666;
		line-height: 34rpx;
	}
	.productInformation-btm {
		margin: 40rpx;
		height: 92rpx;
		line-height: 92rpx;
		text-align: center;
		background: #5DD4D6;
		border-radius: 46rpx;
		font-size: 36rpx;
		color: #FFFFFF;
	}
	.productInformation-btm-false {
		opacity: 0.5;
	}
</style>
